]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell-screenshot: Add utility function to check when draw the cursor
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Wed, 13 Feb 2019 01:13:47 +0000 (02:13 +0100)
committerJonas Ådahl <jadahl@gmail.com>
Fri, 1 Mar 2019 17:12:53 +0000 (17:12 +0000)
Don't repeat the same logic in multiple places, just set include_cursor to the
proper value once depending on the settings we have.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/5

src/shell-screenshot.c

index a1fba9e4f7380e2824394b8758de510f990444f6..4ad90a1ae88e6dbe49e665b582974215d10413c9 100644 (file)
@@ -256,6 +256,17 @@ do_grab_screenshot (ShellScreenshot *screenshot,
   g_free (captures);
 }
 
+static gboolean
+should_draw_cursor_image (void)
+{
+  g_autoptr (GSettings) settings = g_settings_new (A11Y_APPS_SCHEMA);
+
+  if (!g_settings_get_boolean (settings, MAGNIFIER_ACTIVE_KEY))
+    return TRUE;
+
+  return FALSE;
+}
+
 static void
 draw_cursor_image (cairo_surface_t       *surface,
                    cairo_rectangle_int_t  area)
@@ -321,7 +332,6 @@ grab_screenshot (ClutterActor *stage,
 {
   MetaDisplay *display;
   int width, height;
-  GSettings *settings;
   ShellScreenshot *screenshot = g_task_get_source_object (result);
   ShellScreenshotPrivate *priv = screenshot->priv;
   GTask *task;
@@ -375,13 +385,9 @@ grab_screenshot (ClutterActor *stage,
   priv->screenshot_area.width = width;
   priv->screenshot_area.height = height;
 
-  settings = g_settings_new (A11Y_APPS_SCHEMA);
-  if (priv->include_cursor &&
-      !g_settings_get_boolean (settings, MAGNIFIER_ACTIVE_KEY))
+  if (priv->include_cursor)
     draw_cursor_image (priv->image, priv->screenshot_area);
 
-  g_object_unref (settings);
-
   g_signal_handlers_disconnect_by_func (stage, grab_screenshot, result);
 
   task = g_task_new (screenshot, NULL, on_screenshot_written, result);
@@ -417,7 +423,6 @@ grab_window_screenshot (ClutterActor *stage,
   ShellScreenshot *screenshot = g_task_get_source_object (result);
   ShellScreenshotPrivate *priv = screenshot->priv;
   GTask *task;
-  GSettings *settings;
   MetaDisplay *display = shell_global_get_display (priv->global);
   MetaWindow *window = meta_display_get_focus_window (display);
   ClutterActor *window_actor;
@@ -446,12 +451,9 @@ grab_window_screenshot (ClutterActor *stage,
   priv->image = meta_shaped_texture_get_image (stex, &clip);
   priv->datetime = g_date_time_new_now_local ();
 
-  settings = g_settings_new (A11Y_APPS_SCHEMA);
-  if (priv->include_cursor && !g_settings_get_boolean (settings, MAGNIFIER_ACTIVE_KEY))
+  if (priv->include_cursor)
     draw_cursor_image (priv->image, priv->screenshot_area);
 
-  g_object_unref (settings);
-
   g_signal_handlers_disconnect_by_func (stage, grab_window_screenshot, result);
   task = g_task_new (screenshot, NULL, on_screenshot_written, result);
   g_task_run_in_thread (task, write_screenshot_thread);
@@ -541,7 +543,7 @@ shell_screenshot_screenshot (ShellScreenshot     *screenshot,
   g_task_set_source_tag (result, shell_screenshot_screenshot);
 
   priv->filename = g_strdup (filename);
-  priv->include_cursor = include_cursor;
+  priv->include_cursor = include_cursor && should_draw_cursor_image ();
 
   stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));
 
@@ -715,7 +717,7 @@ shell_screenshot_screenshot_window (ShellScreenshot     *screenshot,
 
   priv->filename = g_strdup (filename);
   priv->include_frame = include_frame;
-  priv->include_cursor = include_cursor;
+  priv->include_cursor = include_cursor && should_draw_cursor_image ();
 
   stage = CLUTTER_ACTOR (shell_global_get_stage (priv->global));